
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>一、基础概念 · 计算机笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="海拉尔的三角">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro-fixed/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-ancre-navigation/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex-pro/katex.min.css">
                
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-terminull-light/terminull.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="keyword_withNum.html" />
    
    
    <link rel="prev" href="../cpp.html" />
    

    
        <link rel="shortcut icon" href="image/ico.png" type="image/x-icon">
    
    
    
    
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="image/ico.png">
    
    
        
    
    
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://github.com/spite-triangle" target="_blank" class="custom-link">Github</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../cpp.html">
            
                <a href="../cpp.html">
            
                    
                    C/C++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="2.1.1" data-path="foundation_withNum.html">
            
                <a href="foundation_withNum.html">
            
                    
                    一、基础概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="keyword_withNum.html">
            
                <a href="keyword_withNum.html">
            
                    
                    二、关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="point_reference_withNum.html">
            
                <a href="point_reference_withNum.html">
            
                    
                    三、指针与引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="oop_withNum.html">
            
                <a href="oop_withNum.html">
            
                    
                    四、面向对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="memory_withNum.html">
            
                <a href="memory_withNum.html">
            
                    
                    五、内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="process_withNum.html">
            
                <a href="process_withNum.html">
            
                    
                    六、进程与线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="locks_withNum.html">
            
                <a href="locks_withNum.html">
            
                    
                    七、锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="stl_withNum.html">
            
                <a href="stl_withNum.html">
            
                    
                    八、STL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="dataStruction_withNum.html">
            
                <a href="dataStruction_withNum.html">
            
                    
                    九、数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="array_list_withNum.html">
            
                <a href="array_list_withNum.html">
            
                    
                    十、数组链表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="find_withNum.html">
            
                <a href="find_withNum.html">
            
                    
                    十一、目标查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="tree_withNum.html">
            
                <a href="tree_withNum.html">
            
                    
                    十二、树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="binaryTree_withNum.html">
            
                <a href="binaryTree_withNum.html">
            
                    
                    十三、二叉树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="dynamicProgram_withNum.html">
            
                <a href="dynamicProgram_withNum.html">
            
                    
                    十四、动态规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="backtracking_withNum.html">
            
                <a href="backtracking_withNum.html">
            
                    
                    十五、回溯算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="monotoneStack_withNum.html">
            
                <a href="monotoneStack_withNum.html">
            
                    
                    十六、单调栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="toollib_withNum.html">
            
                <a href="toollib_withNum.html">
            
                    
                    附录 工具库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../../MySQL/mysql.html">
            
                <a href="../../MySQL/mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../../MySQL/chapter/introduction_withNum.html">
            
                <a href="../../MySQL/chapter/introduction_withNum.html">
            
                    
                    一、简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../../MySQL/chapter/foundation_withNum.html">
            
                <a href="../../MySQL/chapter/foundation_withNum.html">
            
                    
                    二、控制台操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../../MySQL/chapter/operatorDB_withNum.html">
            
                <a href="../../MySQL/chapter/operatorDB_withNum.html">
            
                    
                    三、数据库、表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../../MySQL/chapter/operatorData_withNum.html">
            
                <a href="../../MySQL/chapter/operatorData_withNum.html">
            
                    
                    四、数据操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="../../MySQL/chapter/transaction_withNum.html">
            
                <a href="../../MySQL/chapter/transaction_withNum.html">
            
                    
                    五、事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6" data-path="../../MySQL/chapter/index_withNum.html">
            
                <a href="../../MySQL/chapter/index_withNum.html">
            
                    
                    六、索引
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.7" data-path="../../MySQL/chapter/authority_withNum.html">
            
                <a href="../../MySQL/chapter/authority_withNum.html">
            
                    
                    七、权限管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.8" data-path="../../MySQL/chapter/backup_withNum.html">
            
                <a href="../../MySQL/chapter/backup_withNum.html">
            
                    
                    八、备份
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../linux/linux.html">
            
                <a href="../../linux/linux.html">
            
                    
                    Linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../../linux/chapter/foundation_withNum.html">
            
                <a href="../../linux/chapter/foundation_withNum.html">
            
                    
                    一、原理知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../../linux/chapter/command_withNum.html">
            
                <a href="../../linux/chapter/command_withNum.html">
            
                    
                    二、指令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../tcp_udp/tcp_upd.html">
            
                <a href="../../tcp_udp/tcp_upd.html">
            
                    
                    网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="../../tcp_udp/chapter/foundation_withNum.html">
            
                <a href="../../tcp_udp/chapter/foundation_withNum.html">
            
                    
                    一、网络通讯基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                <a href="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                    
                    二、tcp/udp
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >一、基础概念</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><span class="title-icon "></span><a href="#&#x57FA;&#x7840;&#x77E5;&#x8BC6;"><b></b>&#x57FA;&#x7840;&#x77E5;&#x8BC6;</a></li><li><span class="title-icon "></span><a href="#1-c&#x8BED;&#x8A00;&#x6587;&#x4EF6;"><b></b>1. c&#x8BED;&#x8A00;&#x6587;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#2-c&#x6587;&#x4EF6;"><b></b>2. c++&#x6587;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#3-&#x5185;&#x8054;&#x51FD;&#x6570;"><b></b>3. &#x5185;&#x8054;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#4-c&#x4E0E;c&#x533A;&#x522B;"><b></b>4. c&#x4E0E;c++&#x533A;&#x522B;</a></li><ul><li><span class="title-icon "></span><a href="#41-int-f-&#x4E0E;-int-fvoid-&#x533A;&#x522B;"><b></b>4.1. int f() &#x4E0E; int f(void) &#x533A;&#x522B;</a></li><li><span class="title-icon "></span><a href="#42-&#x4E09;&#x76EE;&#x8FD0;&#x7B97;"><b></b>4.2. &#x4E09;&#x76EE;&#x8FD0;&#x7B97;</a></li></ul><li><span class="title-icon "></span><a href="#5-&#x91CD;&#x5B9A;&#x4E49;"><b></b>5. &#x91CD;&#x5B9A;&#x4E49;</a></li><ul><li><span class="title-icon "></span><a href="#51-&#x7ED3;&#x6784;&#x4F53;"><b></b>5.1. &#x7ED3;&#x6784;&#x4F53;</a></li></ul><li><span class="title-icon "></span><a href="#6-main&#x51FD;&#x6570;"><b></b>6. main&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#7-&#x7F16;&#x8BD1;&#x5668;"><b></b>7. &#x7F16;&#x8BD1;&#x5668;</a></li><li><span class="title-icon "></span><a href="#8-&#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;"><b></b>8. &#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;</a></li><li><span class="title-icon "></span><a href="#9-&#x52A8;&#x6001;&#x94FE;&#x63A5;&#x4E0E;&#x9759;&#x6001;&#x94FE;&#x63A5;"><b></b>9. &#x52A8;&#x6001;&#x94FE;&#x63A5;&#x4E0E;&#x9759;&#x6001;&#x94FE;&#x63A5;</a></li><li><span class="title-icon "></span><a href="#10-&#x5B9A;&#x4E49;&#x4E0E;&#x58F0;&#x660E;"><b></b>10. &#x5B9A;&#x4E49;&#x4E0E;&#x58F0;&#x660E;</a></li><li><span class="title-icon "></span><a href="#11-&#x6A21;&#x5757;&#x5316;&#x8BBE;&#x8BA1;"><b></b>11. &#x6A21;&#x5757;&#x5316;&#x8BBE;&#x8BA1;</a></li><li><span class="title-icon "></span><a href="#12-&#x6CDB;&#x578B;"><b></b>12. &#x6CDB;&#x578B;</a></li><li><span class="title-icon "></span><a href="#13-&#x7C7B;&#x578B;&#x5B89;&#x5168;"><b></b>13. &#x7C7B;&#x578B;&#x5B89;&#x5168;</a></li><li><span class="title-icon "></span><a href="#14-&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><b></b>14. &#x7C7B;&#x578B;&#x8F6C;&#x6362;</a></li><ul><li><span class="title-icon "></span><a href="#141-c&#x98CE;&#x683C;"><b></b>14.1. c&#x98CE;&#x683C;</a></li><ul><li><span class="title-icon "></span><a href="#1411-&#x81EA;&#x52A8;&#x8F6C;&#x6362;"><b></b>14.1.1. &#x81EA;&#x52A8;&#x8F6C;&#x6362;</a></li><li><span class="title-icon "></span><a href="#1412-&#x6DF7;&#x5408;&#x6570;&#x5B66;&#x8FD0;&#x7B97;"><b></b>14.1.2. &#x6DF7;&#x5408;&#x6570;&#x5B66;&#x8FD0;&#x7B97;</a></li><li><span class="title-icon "></span><a href="#1413-&#x5F3A;&#x5236;&#x8F6C;&#x6362;"><b></b>14.1.3. &#x5F3A;&#x5236;&#x8F6C;&#x6362;</a></li><li><span class="title-icon "></span><a href="#1414-&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x53EA;&#x662F;&#x4E34;&#x65F6;&#x6027;&#x7684;"><b></b>14.1.4. &#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x53EA;&#x662F;&#x4E34;&#x65F6;&#x6027;&#x7684;</a></li></ul><li><span class="title-icon "></span><a href="#142-c&#x7C7B;&#x578B;&#x8F6C;&#x5316;"><b></b>14.2. c++&#x7C7B;&#x578B;&#x8F6C;&#x5316;</a></li><ul><li><span class="title-icon "></span><a href="#1421-&#x539F;&#x56E0;"><b></b>14.2.1. &#x539F;&#x56E0;</a></li><li><span class="title-icon "></span><a href="#1422-&#x5206;&#x7C7B;"><b></b>14.2.2. &#x5206;&#x7C7B;</a></li><li><span class="title-icon "></span><a href="#1423-staticcast-&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><b></b>14.2.3. static_cast &#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;</a></li><li><span class="title-icon "></span><a href="#1424-dynamiccast"><b></b>14.2.4. dynamic_cast</a></li><li><span class="title-icon "></span><a href="#1425-constcast"><b></b>14.2.5. const_cast</a></li><li><span class="title-icon "></span><a href="#1426-reinterpretcast"><b></b>14.2.6. reinterpret_cast</a></li></ul></ul></ul></div><a href="#&#x57FA;&#x7840;&#x77E5;&#x8BC6;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 style="font-size:60px;text-align:center;" id="&#x57FA;&#x7840;&#x77E5;&#x8BC6;"><a name="&#x57FA;&#x7840;&#x77E5;&#x8BC6;" class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x7840;&#x77E5;&#x8BC6;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x57FA;&#x7840;&#x77E5;&#x8BC6;</h1>

<h1 id="1-c&#x8BED;&#x8A00;&#x6587;&#x4EF6;"><a name="1-c&#x8BED;&#x8A00;&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#1-c&#x8BED;&#x8A00;&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1. c&#x8BED;&#x8A00;&#x6587;&#x4EF6;</h1>
<p>&#x5934;&#x6587;&#x4EF6;&#x540E;&#x7F00;&#x540D;&#xFF1A; .h</p>
<p>&#x6E90;&#x6587;&#x4EF6;&#x540E;&#x7F00;&#x540D;&#xFF1A; .c</p>
<h1 id="2-c&#x6587;&#x4EF6;"><a name="2-c&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#2-c&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>2. c++&#x6587;&#x4EF6;</h1>
<p>&#x5934;&#x6587;&#x4EF6;&#x540E;&#x7F00;&#x540D;&#xFF1A; .h, .hpp, .hxx</p>
<p>&#x6E90;&#x6587;&#x4EF6;&#x540E;&#x7F00;&#x540D;&#xFF1A;.cpp, .cc, .cxx, .C .c++</p>
<p>.hpp: &#x58F0;&#x660E;&#x548C;&#x5B9E;&#x73B0;&#x90FD;&#x6709;</p>
<p>.inl: &#x5185;&#x8054;&#x51FD;&#x6570;</p>
<h1 id="3-&#x5185;&#x8054;&#x51FD;&#x6570;"><a name="3-&#x5185;&#x8054;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#3-&#x5185;&#x8054;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x5185;&#x8054;&#x51FD;&#x6570;</h1>
<p>&#x2003;&#x2003;&#x4F7F;&#x7528;inline&#x4FEE;&#x9970;&#x7684;<font color="#4c9df8">&#x5177;&#x4F53;&#x51FD;&#x6570;&#x5B9E;&#x73B0;&#xFF0C;&#x975E;&#x58F0;&#x660E;</font>&#x3002;<font color="#f44336">&#x7F16;&#x8BD1;&#x671F;&#x95F4;</font>&#x5BF9;&#x4E8E;&#x7F16;&#x8BD1;&#x5668;&#x627F;&#x8BA4;&#x7684;inline&#x51FD;&#x6570;&#xFF0C;&#x5C06;&#x4F1A;&#x76F4;&#x63A5;&#x628A;&#x4EE3;&#x7801;&#x62F7;&#x8D1D;&#x5230;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x4F4D;&#x7F6E;&#x3002;</p>
<ul>
<li>&#x5EFA;&#x8BAE;&#x6027;&#x8D28;&#x7684;&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x53EA;&#x6709;&#x7B80;&#x5355;&#x7684;&#x51FD;&#x6570;&#x4F1A;&#x88AB;&#x7F16;&#x8BD1;&#x5668;&#x627F;&#x8BA4;&#x3002;</li>
<li>&#x9ED8;&#x8BA4;&#x5730;&#xFF0C;&#x7C7B;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x6240;&#x6709;&#x51FD;&#x6570;&#xFF0C;&#x9664;&#x4E86;<strong>&#x865A;&#x51FD;&#x6570;</strong>&#x4E4B;&#x5916;&#xFF0C;&#x4F1A;&#x9690;&#x5F0F;&#x5730;&#x6216;&#x81EA;&#x52A8;&#x5730;&#x5F53;&#x6210;&#x5185;&#x8054;&#x51FD;&#x6570;; <strong>&#x865A;&#x51FD;&#x6570;&#x4E5F;&#x80FD;&#x7528;inline&#x4FEE;&#x9970;&#xFF0C;&#x5EFA;&#x8BAE;&#x6027;&#x8D28;&#x7684;&#x3002;</strong></li>
<li>&#x6CDB;&#x578B;&#x5B9A;&#x4E49;</li>
</ul>
<h1 id="4-c&#x4E0E;c&#x533A;&#x522B;"><a name="4-c&#x4E0E;c&#x533A;&#x522B;" class="anchor-navigation-ex-anchor" href="#4-c&#x4E0E;c&#x533A;&#x522B;"><i class="fa fa-link" aria-hidden="true"></i></a>4. c&#x4E0E;c++&#x533A;&#x522B;</h1>
<ul>
<li><code>C</code>&#x662F;&#x9762;&#x5411;&#x8FC7;&#x7A0B;&#x7684;&#x8BED;&#x8A00;&#xFF0C;<code>C++</code>&#x662F;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7684;&#x8BED;&#x8A00;</li>
<li><code>C++</code>&#x4E2D;<code>new</code>&#x548C;<code>delete</code>&#x662F;&#x5BF9;&#x5185;&#x5B58;&#x5206;&#x914D;&#x7684;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x53D6;&#x4EE3;&#x4E86;<code>C</code>&#x4E2D;&#x7684;&#x5E93;&#x51FD;&#x6570;<code>malloc</code>&#x548C;<code>free</code></li>
<li><code>C++</code>&#x4E2D;&#x6709;&#x5F15;&#x7528;&#x7684;&#x6982;&#x5FF5;&#xFF0C;<code>C</code>&#x4E2D;&#x6CA1;&#x6709;</li>
<li><code>C++</code>&#x5F15;&#x5165;&#x4E86;&#x7C7B;&#x7684;&#x6982;&#x5FF5;&#xFF0C;<code>C</code>&#x4E2D;&#x6CA1;&#x6709;</li>
<li><code>C++</code>&#x6709;&#x51FD;&#x6570;&#x91CD;&#x8F7D;&#xFF0C;<code>C</code>&#x6CA1;&#x6709;&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x300C;&#x6807;&#x51C6;&#x5E93;&#x51FD;&#x6570;&#x7684;&#x91CD;&#x5B9A;&#x5411;&#x300D;</li>
<li><code>C</code>&#x53D8;&#x91CF;&#x53EA;&#x80FD;&#x5728;&#x51FD;&#x6570;&#x7684;&#x5F00;&#x5934;&#x5904;&#x58F0;&#x660E;&#x548C;&#x5B9A;&#x4E49;&#x300C;&#x65E7;&#x7248;&#x7F16;&#x8BD1;&#x5668;&#x300D;&#xFF1B;&#x800C;<code>C++</code>&#x968F;&#x65F6;&#x5B9A;&#x4E49;&#x968F;&#x65F6;&#x4F7F;&#x7528;</li>
</ul>
<h2 id="41-int-f-&#x4E0E;-int-fvoid-&#x533A;&#x522B;"><a name="41-int-f-&#x4E0E;-int-fvoid-&#x533A;&#x522B;" class="anchor-navigation-ex-anchor" href="#41-int-f-&#x4E0E;-int-fvoid-&#x533A;&#x522B;"><i class="fa fa-link" aria-hidden="true"></i></a>4.1. <code>int f()</code> &#x4E0E; <code>int f(void)</code> &#x533A;&#x522B;</h2>
<p><strong><code>c</code>&#x8BED;&#x8A00;&#xFF1A;</strong></p>
<ul>
<li><code>int f()</code> : &#x8868;&#x793A;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;<code>int</code>&#xFF0C;&#x63A5;&#x53D7;&#x4EFB;&#x610F;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;</li>
<li><code>int f(void)</code>: &#x8868;&#x793A;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;<code>int</code>&#x7684;&#x65E0;&#x53C2;&#x51FD;&#x6570;</li>
</ul>
<p><strong><code>c++</code>&#x4E2D;&#xFF1A;</strong></p>
<ul>
<li><code>int f()</code>&#x548C; <code>int f(void)</code>&#xFF1A;&#x90FD;&#x8868;&#x793A;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;<code>int</code>&#x7684;&#x65E0;&#x53C2;&#x51FD;&#x6570;</li>
</ul>
<h2 id="42-&#x4E09;&#x76EE;&#x8FD0;&#x7B97;"><a name="42-&#x4E09;&#x76EE;&#x8FD0;&#x7B97;" class="anchor-navigation-ex-anchor" href="#42-&#x4E09;&#x76EE;&#x8FD0;&#x7B97;"><i class="fa fa-link" aria-hidden="true"></i></a>4.2. &#x4E09;&#x76EE;&#x8FD0;&#x7B97;</h2>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> b <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
<span class="token punctuation">(</span>a<span class="token operator">&lt;</span>b <span class="token operator">?</span> a <span class="token operator">:</span> b<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token punctuation">(</span>a<span class="token operator">&lt;</span>b <span class="token operator">?</span> <span class="token number">1</span> <span class="token operator">:</span> b<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>  <span class="token comment">//&#x9519;&#x8BEF;</span>
</code></pre>
<ul>
<li><code>c</code>&#x8BED;&#x8A00;&#xFF1A;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x4E0D;&#x80FD;&#x4F5C;&#x4E3A;&#x5DE6;&#x503C;</li>
<li><code>c++</code>&#xFF1A;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;&#x53EF;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x53D8;&#x91CF;&#x672C;&#x8EAB;&#xFF0C;&#x65E2;&#x53EF;&#x4F5C;&#x4E3A;&#x53F3;&#x503C;&#x4F7F;&#x7528;&#xFF0C;&#x53C8;&#x53EF;&#x4F5C;&#x4E3A;&#x5DE6;&#x503C;&#x4F7F;&#x7528;<ul>
<li><strong>&#x6CE8;&#x610F;</strong>&#xFF1A;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;&#x53EF;&#x80FD;&#x8FD4;&#x56DE;&#x7684;&#x4E4B;&#x4E2D;&#x5982;&#x679C;&#x6709;&#x4E00;&#x4E2A;&#x662F;&#x5E38;&#x91CF;&#x503C;&#xFF0C;&#x5219;&#x4E0D;&#x80FD;&#x4F5C;&#x4E3A;&#x5DE6;&#x503C;</li>
</ul>
</li>
</ul>
<h1 id="5-&#x91CD;&#x5B9A;&#x4E49;"><a name="5-&#x91CD;&#x5B9A;&#x4E49;" class="anchor-navigation-ex-anchor" href="#5-&#x91CD;&#x5B9A;&#x4E49;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x91CD;&#x5B9A;&#x4E49;</h1>
<p>&#x2003;&#x2003; <strong><code>#include</code>&#x4F1A;&#x5C06;&#x5934;&#x6587;&#x4EF6;&#x590D;&#x5236;&#xFF0C;&#x540C;&#x4E00;&#x4E2A;&#x4E1C;&#x897F;&#x5934;&#x6587;&#x4EF6;&#x5B9E;&#x73B0;&#x4E00;&#x6B21;&#xFF0C;&#x6E90;&#x6587;&#x4EF6;&#x5B9E;&#x73B0;&#x4E00;&#x6B21;&#x5C31;&#x4F1A;&#x89E6;&#x53D1;&#x91CD;&#x5B9A;&#x4E49;&#x3002;</strong></p>
<h2 id="51-&#x7ED3;&#x6784;&#x4F53;"><a name="51-&#x7ED3;&#x6784;&#x4F53;" class="anchor-navigation-ex-anchor" href="#51-&#x7ED3;&#x6784;&#x4F53;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1. &#x7ED3;&#x6784;&#x4F53;</h2>
<p><span style="font-size:24px;font-weight:bold" class="section2">1. c</span></p>
<pre class="language-"><code class="lang-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token keyword">struct</span> <span class="token class-name">Test</span>
<span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token punctuation">;</span>
    <span class="token keyword">int</span> b<span class="token punctuation">;</span>
    <span class="token keyword">const</span> <span class="token keyword">int</span> c<span class="token punctuation">;</span>
    <span class="token keyword">void</span> <span class="token punctuation">(</span><span class="token operator">*</span>fcn<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token keyword">const</span> <span class="token operator">*</span>argv<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">struct</span> <span class="token class-name">Test</span> t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>t<span class="token punctuation">.</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><span style="font-size:24px;font-weight:bold" class="section2">2. c++</span></p>
<pre class="language-"><code class="lang-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>

<span class="token keyword">struct</span> <span class="token class-name">Test</span>
<span class="token punctuation">{</span>
<span class="token keyword">private</span><span class="token operator">:</span>
    <span class="token keyword">int</span> a<span class="token punctuation">;</span>
<span class="token keyword">public</span><span class="token operator">:</span>
    <span class="token keyword">int</span> b<span class="token punctuation">;</span>
    <span class="token keyword">const</span> <span class="token keyword">int</span> c<span class="token punctuation">;</span>
    <span class="token keyword">static</span> <span class="token keyword">int</span> d<span class="token punctuation">;</span>

    <span class="token function">Test</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">,</span><span class="token keyword">int</span> c<span class="token punctuation">)</span>
    <span class="token operator">:</span><span class="token function">c</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token operator">-&gt;</span>a <span class="token operator">=</span> a<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token operator">-&gt;</span>b <span class="token operator">=</span> b<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">virtual</span> <span class="token keyword">void</span> <span class="token function">fcn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;parent \n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">~</span><span class="token function">Test</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">int</span> Test<span class="token double-colon punctuation">::</span>d <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>

<span class="token keyword">struct</span> <span class="token class-name">Son</span><span class="token operator">:</span><span class="token base-clause"><span class="token keyword">public</span> <span class="token class-name">Test</span></span><span class="token punctuation">{</span>
    <span class="token function">Son</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">,</span><span class="token keyword">int</span> c<span class="token punctuation">)</span>
    <span class="token operator">:</span> <span class="token function">Test</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>

    <span class="token punctuation">}</span>

    <span class="token keyword">virtual</span> <span class="token keyword">void</span> <span class="token function">fcn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;son \n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token keyword">const</span> <span class="token operator">*</span>argv<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    Son <span class="token function">s</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    Test<span class="token operator">&amp;</span> t <span class="token operator">=</span> s<span class="token punctuation">;</span>
    t<span class="token punctuation">.</span><span class="token function">fcn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;b: %d c: %d d: %d\n&quot;</span><span class="token punctuation">,</span>s<span class="token punctuation">.</span>b<span class="token punctuation">,</span>s<span class="token punctuation">.</span>c<span class="token punctuation">,</span>s<span class="token punctuation">.</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><span style="font-size:24px;font-weight:bold" class="section2">3. &#x5BF9;&#x6BD4;&#x603B;&#x7ED3;</span></p>
<table>
<thead>
<tr>
<th>&#x9879;&#x76EE;</th>
<th><code>c</code></th>
<th><code>c++</code></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>const</code>&#x53D8;&#x91CF;</td>
<td>&#x53EF;&#x4EE5;</td>
<td>&#x53EF;&#x4EE5;</td>
</tr>
<tr>
<td><code>const</code>&#x53D8;&#x91CF;&#x521D;&#x59CB;&#x5316;</td>
<td>&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x65F6;<code>{,,}</code>&#x521D;&#x59CB;&#x5316;</td>
<td>&#x521D;&#x59CB;&#x5316;&#x53C2;&#x6570;&#x5217;&#x8868;</td>
</tr>
<tr>
<td><code>static</code> &#x53D8;&#x91CF;</td>
<td>&#x4E0D;&#x884C;</td>
<td>&#x53EF;&#x4EE5;</td>
</tr>
<tr>
<td>&#x51FD;&#x6570;&#x5B9A;&#x4E49;</td>
<td>&#x51FD;&#x6570;&#x6307;&#x9488;</td>
<td>&#x76F4;&#x63A5;&#x5B9A;&#x4E49;</td>
</tr>
<tr>
<td>&#x7ED3;&#x6784;&#x4F53;&#x58F0;&#x660E;</td>
<td><code>struct &#x540D;&#x5B57; &#x53D8;&#x91CF;;</code></td>
<td><code>&#x540D;&#x5B57; &#x53D8;&#x91CF;;</code></td>
</tr>
<tr>
<td>&#x8BBF;&#x95EE;&#x6743;&#x9650;</td>
<td>&#x6CA1;&#x6709;</td>
<td>&#x6709;</td>
</tr>
<tr>
<td>&#x62F7;&#x8D1D;&#x6784;&#x9020;&#xFF0C;&#x6784;&#x9020;&#x3001;&#x6790;&#x6784;&#x51FD;&#x6570;</td>
<td>&#x6CA1;&#x6709;</td>
<td>&#x6709;</td>
</tr>
<tr>
<td>&#x7EE7;&#x627F;</td>
<td>&#x6CA1;&#x6709;</td>
<td>&#x6709;</td>
</tr>
<tr>
<td>&#x591A;&#x6001;</td>
<td>&#x6CA1;&#x6709;</td>
<td>&#x6709;</td>
</tr>
</tbody>
</table>
<p><span style="font-size:24px;font-weight:bold" class="section2">4. &#x6076;&#x5FC3;&#x8FFD;&#x52A0;</span></p>
<pre class="language-"><code class="lang-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>

<span class="token keyword">struct</span> <span class="token class-name">Test</span><span class="token punctuation">{</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">class</span> <span class="token class-name">A</span><span class="token punctuation">{</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token keyword">const</span> <span class="token operator">*</span>argv<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;c++ struct: %d, c++ class %d \n&quot;</span><span class="token punctuation">,</span> <span class="token keyword">sizeof</span><span class="token punctuation">(</span>Test<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">sizeof</span><span class="token punctuation">(</span>A<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class="language-"><code class="lang-c"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>

<span class="token keyword">struct</span> <span class="token class-name">Test</span>
<span class="token punctuation">{</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token keyword">const</span> <span class="token operator">*</span>argv<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span><span class="token keyword">sizeof</span><span class="token punctuation">(</span><span class="token keyword">struct</span> <span class="token class-name">Test</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<blockquote>
<p>[!note|style:flat]</p>
<ul>
<li><strong>c++: &#x7A7A;&#x7ED3;&#x6784;&#x4F53;&#x4E0E;&#x7A7A;&#x7C7B;&#x7684;<code>sizeof</code>&#x4E3A;<code>1</code>&#x3002;</strong></li>
<li><strong>c: &#x7A7A;&#x7ED3;&#x6784;&#x4F53;&#x7684;<code>sizeof</code>&#x4E3A;<code>0</code></strong></li>
<li><code>C++</code>&#x6807;&#x51C6;&#x89C4;&#x5B9A;&#x7C7B;&#x7684;&#x5927;&#x5C0F;&#x4E0D;&#x4E3A;<code>0</code>&#xFF0C;&#x7A7A;&#x7C7B;&#x7684;&#x5927;&#x5C0F;&#x4E3A;<code>1</code>&#xFF0C;&#x5F53;&#x7C7B;&#x4E0D;&#x5305;&#x542B;&#x865A;&#x51FD;&#x6570;&#x548C;&#x975E;&#x9759;&#x6001;&#x6570;&#x636E;&#x6210;&#x5458;&#x65F6;&#xFF0C;&#x5176;&#x5BF9;&#x8C61;&#x5927;&#x5C0F;&#x4E5F;&#x4E3A;<code>1</code></li>
</ul>
</blockquote>
<h1 id="6-main&#x51FD;&#x6570;"><a name="6-main&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#6-main&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>6. <code>main</code>&#x51FD;&#x6570;</h1>
<ul>
<li><code>int argc</code> : &#x4F20;&#x5165;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#xFF0C;<strong>&#x9ED8;&#x8BA4;&#x4E3A;1</strong></li>
<li><code>const char * argv[]</code> : &#x8F93;&#x5165;&#x7684;&#x53C2;&#x6570;&#x5217;&#x8868;<ul>
<li><strong>&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x6570;&#x7EC4;</strong></li>
<li><code>argv[0]</code> : &#x88AB;&#x6267;&#x884C;&#x7A0B;&#x5E8F;&#xFF08;.exe&#x6587;&#x4EF6;&#xFF09;&#x6240;&#x5728;&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x3002;</li>
</ul>
</li>
</ul>
<h1 id="7-&#x7F16;&#x8BD1;&#x5668;"><a name="7-&#x7F16;&#x8BD1;&#x5668;" class="anchor-navigation-ex-anchor" href="#7-&#x7F16;&#x8BD1;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x7F16;&#x8BD1;&#x5668;</h1>
<p>gcc&#x4E0E;g++&#x8FDB;&#x884C;&#x6587;&#x4EF6;&#x7F16;&#x8BD1;&#x65F6;&#xFF0C;&#x4F1A;&#x4E92;&#x76F8;&#x8C03;&#x7528;&#xFF0C;<strong>&#x4F46;&#x662F;&#x7F16;&#x8BD1;.c&#x6587;&#x4EF6;&#x9664;&#x5916;</strong>&#xFF1B;<strong>&#x5728;&#x94FE;&#x63A5;&#x65F6;&#xFF0C;&#x4E0D;&#x4F1A;&#x4E92;&#x76F8;&#x8C03;&#x7528;&#x3002;</strong></p>
<ul>
<li><strong>&#x9884;&#x5904;&#x7406;</strong>: <code>-E</code>&#xFF0C;&#x5904;&#x7406;&#x5B8F;</li>
<li><strong>&#x7F16;&#x8BD1;</strong>:<code>-S</code>&#xFF0C;&#x751F;&#x6210;&#x6C47;&#x7F16;</li>
<li><strong>&#x6C47;&#x7F16;</strong>:<code>-C</code>&#xFF0C;&#x751F;&#x6210;&#x4E8C;&#x8FDB;&#x5236;</li>
<li><strong>&#x94FE;&#x63A5;</strong>:<code>-O</code>&#xFF0C;&#x751F;&#x6210;&#x76EE;&#x6807;&#x6587;&#x4EF6;</li>
</ul>
<h1 id="8-&#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;"><a name="8-&#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;" class="anchor-navigation-ex-anchor" href="#8-&#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;"><i class="fa fa-link" aria-hidden="true"></i></a>8. &#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;</h1>
<blockquote>
<p>[!tip]
<strong>&#x5B9A;&#x4E49;&#xFF1A;&#x8FDB;&#x7A0B;&#x5728;&#x54EA;&#x4E2A;&#x8DEF;&#x5F84;&#x4E0B;&#x88AB;&#x8FD0;&#x884C;&#x8D77;&#x6765;&#x54EA;&#x4E2A;&#x8DEF;&#x5F84;&#x5C31;&#x662F;&#x8FDB;&#x7A0B;&#x7684;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;(Current Woring Directory, CWD)&#x3002;</strong></p>
<ul>
<li><strong>&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#xFF1A;</strong> &#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x5C31;&#x662F;&#x300C;&#x76F8;&#x5BF9;&#x300D;&#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x800C;&#x8A00;&#x7684;&#x3002;</li>
</ul>
</blockquote>
<p></p><div class="terminull">
    <div class="terminullMenu">
      <div class="terminullButtons terminullClose"></div>
      <div class="terminullButtons terminullMinimize"></div>
      <div class="terminullButtons terminullZoom"></div>
    </div>
    <div class="terminullScreen">
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:/home/triangle/test</span>$ 
          <span class="terminullCommand">./a.out</span>
           
            <span class="terminullComment"># a.out &#x7684;&#x8FDB;&#x7A0B;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x5C31;&#x662F; /home/triangle/test</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`./a.out`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">pwdx pid&#x53F7;</span>
           
            <span class="terminullComment"># &#x67E5;&#x770B;&#x8FDB;&#x7A0B;&#x7684;&#x5DE5;&#x4F5C;&#x8DEF;&#x5F84;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`pwdx pid&#x53F7;`)"></i>
          <span class="terminullOutput"></span>
        
    </div>
</div><p></p>
<h1 id="9-&#x52A8;&#x6001;&#x94FE;&#x63A5;&#x4E0E;&#x9759;&#x6001;&#x94FE;&#x63A5;"><a name="9-&#x52A8;&#x6001;&#x94FE;&#x63A5;&#x4E0E;&#x9759;&#x6001;&#x94FE;&#x63A5;" class="anchor-navigation-ex-anchor" href="#9-&#x52A8;&#x6001;&#x94FE;&#x63A5;&#x4E0E;&#x9759;&#x6001;&#x94FE;&#x63A5;"><i class="fa fa-link" aria-hidden="true"></i></a>9. &#x52A8;&#x6001;&#x94FE;&#x63A5;&#x4E0E;&#x9759;&#x6001;&#x94FE;&#x63A5;</h1>
<p><span style="font-size:24px;font-weight:bold" class="section2">1. &#x5BF9;&#x6BD4;</span></p>
<ul>
<li><strong>&#x9759;&#x6001;&#x94FE;&#x63A5;</strong><ul>
<li>&#x5728;&#x7F16;&#x8BD1;&#x94FE;&#x63A5;&#x65F6;&#xFF0C;&#x76F4;&#x63A5;&#x5C06;&#x9700;&#x8981;&#x7684;&#x6267;&#x884C;&#x4EE3;&#x7801;&#x62F7;&#x8D1D;&#x5230;&#x8C03;&#x7528;&#x5904;</li>
<li>&#x7A0B;&#x5E8F;&#x53D1;&#x5E03;&#x7684;&#x65F6;&#x5019;&#x5C31;&#x4E0D;&#x9700;&#x8981;&#x4F9D;&#x8D56;&#x5E93;&#xFF0C;&#x4F46;&#x662F;&#x4F53;&#x79EF;&#x53EF;&#x80FD;&#x4F1A;&#x76F8;&#x5BF9;&#x5927;&#x4E00;&#x4E9B;&#x3002;</li>
</ul>
</li>
<li><strong>&#x52A8;&#x6001;&#x94FE;&#x63A5;</strong><ul>
<li>&#x5728;&#x7F16;&#x8BD1;&#x65F6;&#xFF0C;&#x4E0D;&#x76F4;&#x63A5;&#x62F7;&#x8D1D;&#x53EF;&#x6267;&#x884C;&#x4EE3;&#x7801;&#xFF0C;&#x800C;&#x8BB0;&#x5F55;&#x4E00;&#x7CFB;&#x5217;&#x7B26;&#x53F7;&#x548C;&#x53C2;&#x6570;&#xFF0C;&#x5728;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x6216;&#x52A0;&#x8F7D;&#x65F6;&#x5C06;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;&#x4F20;&#x9012;&#x7ED9;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#xFF0C;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x8D1F;&#x8D23;&#x5C06;&#x9700;&#x8981;&#x7684;&#x52A8;&#x6001;&#x5E93;&#x52A0;&#x8F7D;&#x5230;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x7A0B;&#x5E8F;&#x5728;&#x8FD0;&#x884C;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x4EE3;&#x7801;&#x65F6;&#xFF0C;&#x53BB;&#x5171;&#x4EAB;&#x6267;&#x884C;&#x5185;&#x5B58;&#x4E2D;&#x5DF2;&#x7ECF;&#x52A0;&#x8F7D;&#x7684;&#x52A8;&#x6001;&#x5E93;&#x53EF;&#x6267;&#x884C;&#x4EE3;&#x7801;&#xFF0C;&#x6700;&#x7EC8;&#x8FBE;&#x5230;&#x8FD0;&#x884C;&#x65F6;&#x8FDE;&#x63A5;&#x7684;&#x76EE;&#x7684;&#x3002;</li>
<li>&#x591A;&#x4E2A;&#x7A0B;&#x5E8F;&#x53EF;&#x4EE5;&#x5171;&#x4EAB;&#x540C;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#xFF0C;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x5728;&#x78C1;&#x76D8;&#x4E0A;&#x5B58;&#x50A8;&#x591A;&#x4E2A;&#x62F7;&#x8D1D;</li>
<li>&#x8FD0;&#x884C;&#x65F6;&#x52A0;&#x8F7D;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x5F71;&#x54CD;&#x7A0B;&#x5E8F;&#x7684;&#x524D;&#x671F;&#x6267;&#x884C;&#x6027;&#x80FD;</li>
<li>&#x53D1;&#x5E03;&#x7A0B;&#x5E8F;&#x65F6;&#xFF0C;&#x8981;&#x628A;&#x52A8;&#x6001;&#x5E93;&#x4E5F;&#x4E00;&#x8D77;&#x5E26;&#x4E0A;</li>
</ul>
</li>
</ul>
<p><span style="font-size:24px;font-weight:bold" class="section2">2. &#x9759;&#x6001;&#x94FE;&#x63A5;&#x5E93;</span></p>
<sec data-title="&#x6848;&#x4F8B;&#x4EE3;&#x7801;" data-id="example_lib" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;&#x4EE3;&#x7801;<a class="pull-right section atTitle btn btn-default" target="example_lib"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="example_lib"><div class="panel-body">
<p><code>math.h</code></p>
<pre class="language-"><code class="lang-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">ifndef</span> <span class="token expression">__MATH_H__</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name">__MATH_H__</span></span>

<span class="token keyword">extern</span> <span class="token keyword">int</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">endif</span> <span class="token comment">// __MATH_H__</span></span>
</code></pre>
<p><code>math.cpp</code></p>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">int</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> a <span class="token operator">+</span> b<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><code>main.cpp</code></p>
<pre class="language-"><code class="lang-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&quot;math.h&quot;</span></span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token keyword">const</span> <span class="token operator">*</span>argv<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d \n&quot;</span><span class="token punctuation">,</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span><span class="token number">11</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
</div></div></div></sec>
<p></p><div class="terminull">
    <div class="terminullMenu">
      <div class="terminullButtons terminullClose"></div>
      <div class="terminullButtons terminullMinimize"></div>
      <div class="terminullButtons terminullZoom"></div>
    </div>
    <div class="terminullScreen">
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">gcc -c math.cpp</span>
           
            <span class="terminullComment"># &#x751F;&#x6210; .o &#x6587;&#x4EF6;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`gcc -c math.cpp`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">ar rcs libmath.a math.o</span>
           
            <span class="terminullComment"># &#x6253;&#x5305;&#x751F;&#x6210;&#x9759;&#x6001;&#x5E93;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`ar rcs libmath.a math.o`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">gcc main.cpp -L. -lmath</span>
           
            <span class="terminullComment"># &#x4F7F;&#x7528;&#x9759;&#x6001;&#x5E93;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`gcc main.cpp -L. -lmath`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">./a.out</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`./a.out`)"></i>
          <span class="terminullOutput">21</span>
        
    </div>
</div><p></p>
<blockquote>
<p>[!note|style:flat]
<strong><code>-lmath</code>&#xFF1A;&#x5BF9;&#x4E8E;&#x5E93;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x4E0D;&#x8981;&#x52A0; <code>lib</code> &#x548C; <code>.a</code></strong></p>
</blockquote>
<p><span style="font-size:24px;font-weight:bold" class="section2">3. &#x52A8;&#x6001;&#x5E93;</span></p>
<p></p><div class="terminull">
    <div class="terminullMenu">
      <div class="terminullButtons terminullClose"></div>
      <div class="terminullButtons terminullMinimize"></div>
      <div class="terminullButtons terminullZoom"></div>
    </div>
    <div class="terminullScreen">
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">gcc -fPIC -c math.cpp</span>
           
            <span class="terminullComment"># -fPIC &#x8868;&#x793A;&#x751F;&#x6210;&#x4E0E;&#x8DEF;&#x5F84;&#x65E0;&#x5173;&#x7684;&#x4EE3;&#x7801;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`gcc -fPIC -c math.cpp`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">gcc -shared -o libmath.so math.o</span>
           
            <span class="terminullComment"># &#x751F;&#x6210;&#x52A8;&#x6001;&#x5E93;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`gcc -shared -o libmath.so math.o`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">gcc main.cpp -L. -lmath</span>
           
            <span class="terminullComment"># &#x4F7F;&#x7528;&#x52A8;&#x6001;&#x5E93;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`gcc main.cpp -L. -lmath`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">export LD_LIBRARY_PATH=$(pwd)</span>
           
            <span class="terminullComment"># &#x6DFB;&#x52A0;&#x52A8;&#x6001;&#x5E93;&#x67E5;&#x627E;&#x4F4D;&#x7F6E;</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`export LD_LIBRARY_PATH=$(pwd)`)"></i>
          <span class="terminullOutput"></span>
        
          <span class="terminullDirectory">triangle@LEARN_FUCK:~</span>$ 
          <span class="terminullCommand">./a.out</span>
          
          <i class="fa fa-clone t-copy terminullCopyBtn" onclick="copyCommandTerminull(`./a.out`)"></i>
          <span class="terminullOutput">21</span>
        
    </div>
</div><p></p>
<h1 id="10-&#x5B9A;&#x4E49;&#x4E0E;&#x58F0;&#x660E;"><a name="10-&#x5B9A;&#x4E49;&#x4E0E;&#x58F0;&#x660E;" class="anchor-navigation-ex-anchor" href="#10-&#x5B9A;&#x4E49;&#x4E0E;&#x58F0;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>10. &#x5B9A;&#x4E49;&#x4E0E;&#x58F0;&#x660E;</h1>
<ul>
<li><strong>&#x5B9A;&#x4E49;</strong>&#xFF1A;&#x8868;&#x793A;&#x521B;&#x5EFA;&#x53D8;&#x91CF;&#x6216;&#x5206;&#x914D;&#x5B58;&#x50A8;&#x5355;&#x5143;<ul>
<li><strong>&#x5B9A;&#x4E49;&#x5FC5;&#x987B;&#x6709;&#xFF0C;&#x4E14;&#x53EA;&#x80FD;&#x51FA;&#x73B0;&#x4E00;&#x6B21;</strong></li>
</ul>
</li>
<li><strong>&#x58F0;&#x660E;</strong>&#xFF1A;&#x8BF4;&#x660E;&#x53D8;&#x91CF;&#x7684;&#x6027;&#x8D28;&#xFF0C;&#x4F46;&#x5E76;&#x4E0D;&#x5206;&#x914D;&#x5B58;&#x50A8;&#x5355;&#x5143;;&#x5728; <strong>&#x94FE;&#x63A5;</strong> &#x65F6;&#xFF0C;&#x67E5;&#x627E;&#x5177;&#x4F53;&#x5B9A;&#x4E49;&#x3002;<ul>
<li><strong>&#x58F0;&#x660E;&#x53EF;&#x4EE5;&#x51FA;&#x73B0;&#x591A;&#x6B21;</strong></li>
</ul>
</li>
<li><p><strong>&#x53D8;&#x91CF;&#xFF1A;</strong></p>
<pre class="language-"><code class="lang-cpp">  <span class="token comment">// &#x58F0;&#x660E;</span>
    <span class="token keyword">extern</span> <span class="token keyword">int</span> i<span class="token punctuation">;</span>

    <span class="token comment">// &#x58F0;&#x660E;&#x4E86;&#x672A;&#x5B9A;&#x4E49;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x80FD;&#x91CD;&#x590D;&#x58F0;&#x660E;</span>
    <span class="token keyword">class</span> <span class="token class-name">Test</span><span class="token punctuation">{</span>
    <span class="token keyword">public</span><span class="token operator">:</span>
        <span class="token keyword">static</span> <span class="token keyword">int</span> a<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>

    <span class="token comment">// &#x5B9A;&#x4E49;</span>
    <span class="token keyword">int</span> Test<span class="token double-colon punctuation">::</span>a <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token comment">// &#x58F0;&#x660E;&#x53C8;&#x5B9A;&#x4E49;</span>
    <span class="token keyword">int</span> i<span class="token punctuation">;</span>
    <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
    <span class="token keyword">extern</span> <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token comment">// &#x51FD;&#x6570;&#x5916;&#x90E8;&#x624D;&#x80FD;&#x88AB;&#x521D;&#x59CB;&#x5316;</span>
</code></pre>
  <font color="#f44336" style="font-weight:bold">&#x6E90;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x5168;&#x5C40;&#x53D8;&#x91CF; `int a;` &#x5F62;&#x5F0F;&#xFF0C;&#x9ED8;&#x8BA4;&#x4FEE;&#x9970;&#x7B26;&#x4E3A; `extern`&#x3002;</font></li>
<li><strong>&#x51FD;&#x6570;</strong>: &#x5E26;&#x6709;<code>{ }</code>&#x7684;&#x5C31;&#x662F;&#x5B9A;&#x4E49;&#xFF0C;&#x5426;&#x5219;&#x5C31;&#x662F;&#x58F0;&#x660E;&#x3002;</li>
</ul>
<h1 id="11-&#x6A21;&#x5757;&#x5316;&#x8BBE;&#x8BA1;"><a name="11-&#x6A21;&#x5757;&#x5316;&#x8BBE;&#x8BA1;" class="anchor-navigation-ex-anchor" href="#11-&#x6A21;&#x5757;&#x5316;&#x8BBE;&#x8BA1;"><i class="fa fa-link" aria-hidden="true"></i></a>11. &#x6A21;&#x5757;&#x5316;&#x8BBE;&#x8BA1;</h1>
<ol>
<li>&#x6A21;&#x5757;&#x5373;&#x662F;&#x4E00;&#x4E2A;<code>.c</code>&#x6587;&#x4EF6;&#x548C;&#x4E00;&#x4E2A;<code>.h</code>&#x6587;&#x4EF6;&#x7684;&#x7ED3;&#x5408;&#xFF0C;<strong>&#x5934;&#x6587;&#x4EF6;(.h)&#x4E2D;&#x662F;&#x5BF9;&#x4E8E;&#x8BE5;&#x6A21;&#x5757;&#x63A5;&#x53E3;&#x7684;&#x58F0;&#x660E;&#xFF0C;&#x4E00;&#x822C;&#x90FD;&#x7528;extern&#x8FDB;&#x884C;&#x4FEE;&#x9970;</strong>&#xFF1B;</li>
<li>&#x4F9B;&#x7ED9;&#x5176;&#x5B83;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x7684;&#x5916;&#x90E8;&#x51FD;&#x6570;&#x53CA;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x9700;&#x5728;<code>.h</code>&#x4E2D;&#x6587;&#x4EF6;&#x4E2D;&#x51A0;&#x4EE5;<code>extern</code>&#x5173;&#x952E;&#x5B57;&#x58F0;&#x660E;&#xFF1B;</li>
<li>&#x6A21;&#x5757;&#x5185;&#x7684;&#x51FD;&#x6570;&#x548C;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x9700;&#x5728;<code>.c</code>&#x6587;&#x4EF6;&#x5F00;&#x5934;&#x51A0;&#x4EE5;<code>static</code>&#x5173;&#x952E;&#x5B57;&#x58F0;&#x660E;&#xFF1B;</li>
<li><font color="#f44336" style="font-weight:bold">&#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x5728;.h&#x6587;&#x4EF6;&#x4E2D;&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF01;</font></li>
<li>&#x5934;&#x6587;&#x4EF6;&#x4E2D;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x7684;&#x5B9E;&#x4F53;&#xFF0C;<font color="#f44336" style="font-weight:bold">&#x5F97;&#x6709;&#x5934;&#x6587;&#x4EF6;&#x4FDD;&#x62A4;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x91CD;&#x5B9A;&#x4E49;&#x3002;</font><ul>
<li>&#x503C;&#x5728;&#x7F16;&#x8BD1;&#x65F6;&#x5C31;&#x5DF2;&#x77E5;&#x7684; <code>const</code> &#x53D8;&#x91CF;&#x7684;&#x5B9A;&#x4E49;&#x53EF;&#x4EE5;&#x653E;&#x5230;&#x5934;&#x6587;&#x4EF6;&#x4E2D;</li>
<li>&#x7ED3;&#x6784;&#x4F53;&#xFF0C;&#x7C7B;&#x7684;&#x5B9A;&#x4E49;&#x53EF;&#x4EE5;&#x653E;&#x5230;&#x5934;&#x6587;&#x4EF6;&#x4E2D;</li>
<li><code>inline</code> &#x51FD;&#x6570;</li>
</ul>
</li>
</ol>
<h1 id="12-&#x6CDB;&#x578B;"><a name="12-&#x6CDB;&#x578B;" class="anchor-navigation-ex-anchor" href="#12-&#x6CDB;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>12. &#x6CDB;&#x578B;</h1>
<ul>
<li><strong><code>template<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>typename</span> <span class="token attr-name">T,class</span> <span class="token attr-name">A</span><span class="token punctuation">&gt;</span></span></code>: <code>typename , class</code>&#x4F5C;&#x7528;&#x4E00;&#x6837;&#x3002;</strong></li>
<li><span style="color:red;font-weight:bold"> &#x6CDB;&#x578B;&#x7684;&#x5B9A;&#x4E49;&#x548C;&#x5B9E;&#x73B0;&#x5FC5;&#x987B;&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#x3002; </span></li>
</ul>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">class</span> <span class="token class-name">Car</span><span class="token punctuation">{</span>
<span class="token keyword">public</span><span class="token operator">:</span>
    <span class="token comment">// &#x7C7B;&#x578B;&#x522B;&#x540D;</span>
    <span class="token keyword">typedef</span> <span class="token keyword">float</span> Speed<span class="token punctuation">;</span>
    <span class="token comment">// &#x5185;&#x90E8;&#x7C7B;</span>
    <span class="token keyword">class</span> <span class="token class-name">Wheel</span><span class="token punctuation">{</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token keyword">static</span> <span class="token keyword">float</span> price<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">float</span> Car<span class="token double-colon punctuation">::</span>price <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x6CDB;&#x578B;</span>
<span class="token keyword">template</span><span class="token operator">&lt;</span><span class="token keyword">typename</span> <span class="token class-name">T</span><span class="token operator">&gt;</span>
<span class="token keyword">class</span> <span class="token class-name">PrivateCar</span><span class="token punctuation">{</span>
<span class="token keyword">public</span><span class="token operator">:</span>
    <span class="token comment">// &#x5B9A;&#x4E49;&#x53D8;&#x91CF;</span>
    <span class="token keyword">typename</span> <span class="token class-name">T</span><span class="token double-colon punctuation">::</span>Speed v<span class="token punctuation">;</span>
    <span class="token keyword">typename</span> <span class="token class-name">T</span><span class="token double-colon punctuation">::</span>Wheel wheels<span class="token punctuation">;</span>

    <span class="token keyword">float</span> <span class="token function">getPrice</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        T<span class="token double-colon punctuation">::</span>price <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
        <span class="token comment">// &#x53D8;&#x91CF;</span>
        <span class="token keyword">return</span> T<span class="token double-colon punctuation">::</span>price<span class="token punctuation">;</span> 
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>
<h1 id="13-&#x7C7B;&#x578B;&#x5B89;&#x5168;"><a name="13-&#x7C7B;&#x578B;&#x5B89;&#x5168;" class="anchor-navigation-ex-anchor" href="#13-&#x7C7B;&#x578B;&#x5B89;&#x5168;"><i class="fa fa-link" aria-hidden="true"></i></a>13. &#x7C7B;&#x578B;&#x5B89;&#x5168;</h1>
<p><strong>&#x7C7B;&#x578B;&#x5B89;&#x5168;:&#x6307;&#x540C;&#x4E00;&#x6BB5;&#x5185;&#x5B58;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x4F1A;&#x88AB;&#x5F3A;&#x5236;&#x8981;&#x6C42;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x7684;&#x63CF;&#x8FF0;&#x6765;&#x89E3;&#x91CA;(&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x662F;&#x7528;&#x7C7B;&#x578B;&#x6765;&#x89E3;&#x91CA;&#x7684;)&#xFF0C;&#x9664;&#x975E;&#x4F7F;&#x7528;&#x7C7B;&#x578B;&#x5F3A;&#x5236;&#x8F6C;&#x6362;&#x3002;</strong></p>
<blockquote>
<p>[!note|style:flat]
<span style="color:red;font-weight:bold"> <code>c/c++</code> &#x5E76;&#x4E0D;&#x662F;&#x7C7B;&#x578B;&#x5B89;&#x5168;&#x7684;&#x8BED;&#x8A00;&#x3002;</span></p>
</blockquote>
<sec data-title="&#x6848;&#x4F8B;" data-id="example_typeSafe" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;<a class="pull-right section atTitle btn btn-default" target="example_typeSafe"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="example_typeSafe"><div class="panel-body">
<pre class="language-"><code class="lang-cpp"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token comment">// &#x4F7F;&#x7528;&#x6D6E;&#x70B9;&#x7684;&#x5F62;&#x5F0F;&#x8F93;&#x51FA;&#x6574;&#x578B;&#xFF0C;&#x7F16;&#x8BD1;&#x80FD;&#x591F;&#x901A;&#x8FC7;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%f\n&quot;</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 

    <span class="token comment">// d&#x7684;&#x8F93;&#x51FA;&#x503C;&#x5F88;&#x6709;&#x53EF;&#x80FD;&#x4E0D;&#x662F; 5 &#xFF0C;&#x800C;&#x662F;&#x5176;&#x4ED6;&#x503C;&#xFF0C;&#x56E0;&#x4E3A;&#x5B57;&#x8282;&#x6570;&#x9519;&#x4E86;&#x3002;</span>
    <span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span>
    <span class="token keyword">void</span><span class="token operator">*</span> pInt<span class="token operator">=</span><span class="token operator">&amp;</span>i<span class="token punctuation">;</span>
    <span class="token keyword">double</span> d<span class="token operator">=</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token punctuation">(</span><span class="token keyword">double</span><span class="token operator">*</span><span class="token punctuation">)</span>pInt<span class="token punctuation">)</span><span class="token punctuation">;</span>
    cout<span class="token operator">&lt;&lt;</span>d<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
</div></div></div></sec>
<h1 id="14-&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><a name="14-&#x7C7B;&#x578B;&#x8F6C;&#x6362;" class="anchor-navigation-ex-anchor" href="#14-&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>14. &#x7C7B;&#x578B;&#x8F6C;&#x6362;</h1>
<h2 id="141-c&#x98CE;&#x683C;"><a name="141-c&#x98CE;&#x683C;" class="anchor-navigation-ex-anchor" href="#141-c&#x98CE;&#x683C;"><i class="fa fa-link" aria-hidden="true"></i></a>14.1. <code>c</code>&#x98CE;&#x683C;</h2>
<h3 id="1411-&#x81EA;&#x52A8;&#x8F6C;&#x6362;"><a name="1411-&#x81EA;&#x52A8;&#x8F6C;&#x6362;" class="anchor-navigation-ex-anchor" href="#1411-&#x81EA;&#x52A8;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>14.1.1. &#x81EA;&#x52A8;&#x8F6C;&#x6362;</h3>
<p><strong>&#x5C06;&#x4E00;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x8D4B;&#x503C;&#x7ED9;&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x53D8;&#x91CF;&#x65F6;&#x5C31;&#x4F1A;&#x53D1;&#x751F;&#x81EA;&#x52A8;&#x7C7B;&#x578B;&#x8F6C;&#x6362;</strong></p>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">float</span> f <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
</code></pre>
<blockquote>
<p>[!note]</p>
<ol>
<li><strong><code>100</code>&#x5148;&#x8F6C;&#x4E3A;&#x4E00;&#x4E2A;&#x300C;&#x5E26;&#x6709;&#x5E38;&#x6027;&#x7684;&#x4E34;&#x65F6;&#x53D8;&#x91CF;<code>100.0</code>&#x300D;</strong></li>
<li><strong>&#x7136;&#x540E;&#x518D;&#x5C06;&#x300C;&#x5E26;&#x6709;&#x5E38;&#x6027;&#x7684;&#x4E34;&#x65F6;&#x53D8;&#x91CF;<code>100.0</code>&#x300D;&#x8D4B;&#x503C;&#x7ED9;<code>f</code></strong></li>
</ol>
</blockquote>
<h3 id="1412-&#x6DF7;&#x5408;&#x6570;&#x5B66;&#x8FD0;&#x7B97;"><a name="1412-&#x6DF7;&#x5408;&#x6570;&#x5B66;&#x8FD0;&#x7B97;" class="anchor-navigation-ex-anchor" href="#1412-&#x6DF7;&#x5408;&#x6570;&#x5B66;&#x8FD0;&#x7B97;"><i class="fa fa-link" aria-hidden="true"></i></a>14.1.2. &#x6DF7;&#x5408;&#x6570;&#x5B66;&#x8FD0;&#x7B97;</h3>
<p><strong>&#x5728;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x6DF7;&#x5408;&#x8FD0;&#x7B97;&#x4E2D;: &#x5C06;&#x53C2;&#x4E0E;&#x8FD0;&#x7B97;&#x7684;&#x6240;&#x6709;&#x6570;&#x636E;&#x5148;&#x8F6C;&#x6362;&#x4E3A;&#x540C;&#x4E00;&#x79CD;&#x7C7B;&#x578B;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8FDB;&#x884C;&#x8BA1;&#x7B97;&#xFF0C;&#x6700;&#x540E;&#x7ED3;&#x679C;&#x5728;&#x6839;&#x636E;&#x53F3;&#x7AEF;&#x7C7B;&#x578B;&#x8FDB;&#x884C;&#x7C7B;&#x578B;&#x8F6C;&#x5316;&#x3002;</strong></p>
<blockquote>
<p>[!note|style:flat]</p>
<ol>
<li><strong>&#x540C;&#x4E00;&#x7C7B;&#x578B;&#xFF1A;&#x8F6C;&#x6362;&#x6309;&#x6570;&#x636E;&#x957F;&#x5EA6;&#x589E;&#x52A0;&#x7684;&#x65B9;&#x5411;&#x8F6C;&#x6362;&#x540C;&#x4E00;</strong></li>
<li><span style="color:blue;font-weight:bold"> &#x6240;&#x6709;&#x7684;&#x6D6E;&#x70B9;&#x8FD0;&#x7B97;&#x90FD;&#x662F;&#x4EE5;<code>double</code>&#x8FDB;&#x884C;&#x7684;&#xFF0C;&#x5373;&#x4F7F;&#x53EA;&#x6709;<code>float</code> </span></li>
<li><span style="color:blue;font-weight:bold"> <code>char</code>&#x548C; <code>short</code> &#x53C2;&#x4E0E;&#x8FD0;&#x7B97;&#x65F6;&#xFF0C;&#x5FC5;&#x987B;&#x5148;&#x8F6C;&#x6362;&#x6210; <code>int</code> &#x7C7B;&#x578B;&#x3002; </span></li>
<li><span style="color:red;font-weight:bold"> &#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#x503C;&#x5747;&#x662F;&#x300C;&#x5E26;&#x6709;&#x5E38;&#x6027;&#x7684;&#x4E34;&#x65F6;&#x53D8;&#x91CF;&#x300D;&#xFF08;&#x4E0D;&#x7BA1;&#x6700;&#x540E;&#x6709;&#x6CA1;&#x6709;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#xFF09; </span></li>
</ol>
</blockquote>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">1.9</span> <span class="token operator">+</span> <span class="token number">1.6</span>  <span class="token operator">+</span> <span class="token string">&apos;a&apos;</span><span class="token punctuation">;</span> <span class="token comment">// &#x7ED3;&#x679C; 100</span>
<span class="token keyword">float</span> b<span class="token operator">=</span> <span class="token number">10</span> <span class="token operator">/</span> <span class="token number">3</span><span class="token punctuation">;</span> <span class="token comment">// &#x7ED3;&#x679C;&#x4E3A; 3</span>
</code></pre>
<blockquote>
<p><strong>&#x5982;&#x679C;&#x9664;&#x6570;&#x548C;&#x88AB;&#x9664;&#x6570;&#x90FD;&#x662F;&#x6574;&#x6570;&#xFF0C;&#x7ED3;&#x679C;&#x4E3A;&#x6574;&#x6570;; &#x5982;&#x679C;&#x6709;&#x4E00;&#x4E2A;&#x975E;&#x6574;&#x6570;&#xFF0C;&#x5426;&#x5219;&#x4E3A;&#x5C0F;&#x6570;</strong></p>
</blockquote>
<p style="text-align:center;"><a href="../../image/cpp/typeTransform.png" data-lightbox="425de4b5-515f-4619-96f7-ca362e7a4604" data-title="undefined"><img src="../../image/cpp/typeTransform.png" alt="undefined"></a></p>

<h3 id="1413-&#x5F3A;&#x5236;&#x8F6C;&#x6362;"><a name="1413-&#x5F3A;&#x5236;&#x8F6C;&#x6362;" class="anchor-navigation-ex-anchor" href="#1413-&#x5F3A;&#x5236;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>14.1.3. &#x5F3A;&#x5236;&#x8F6C;&#x6362;</h3>
<ul>
<li><span style="color:red;font-weight:bold"> <code>(&#x7C7B;&#x578B;)</code>&#x7684;&#x4F18;&#x5148;&#x7EA7;&#x9AD8;&#x4E8E;&#x8FD0;&#x7B97;&#x7B26; </span><pre class="language-"><code class="lang-cpp">  <span class="token comment">// &#x7ED3;&#x679C;&#x4E3A; 5.0</span>
  <span class="token keyword">float</span> b<span class="token operator">=</span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span><span class="token number">10.2</span> <span class="token operator">/</span><span class="token number">0.2</span><span class="token punctuation">;</span>
</code></pre>
</li>
</ul>
<h3 id="1414-&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x53EA;&#x662F;&#x4E34;&#x65F6;&#x6027;&#x7684;"><a name="1414-&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x53EA;&#x662F;&#x4E34;&#x65F6;&#x6027;&#x7684;" class="anchor-navigation-ex-anchor" href="#1414-&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x53EA;&#x662F;&#x4E34;&#x65F6;&#x6027;&#x7684;"><i class="fa fa-link" aria-hidden="true"></i></a>14.1.4. &#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x53EA;&#x662F;&#x4E34;&#x65F6;&#x6027;&#x7684;</h3>
<blockquote>
<p>[!note|style:flat]
<span style="color:red;font-weight:bold"> &#x65E0;&#x8BBA;&#x662F;&#x81EA;&#x52A8;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x8FD8;&#x662F;&#x5F3A;&#x5236;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#xFF0C;&#x90FD;&#x662F;&#x5148;&#x5C06;&#x539F;&#x6765;&#x7684;&#x503C;&#x8F6C;&#x5316;&#x4E00;&#x4E2A;&#x300C;&#x4E34;&#x65F6;&#x7684;<code>const</code>&#x7C7B;&#x578B;&#x503C;&#x300D;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8FDB;&#x884C;&#x8D4B;&#x503C;&#xFF0C;&#x5E76;&#x4E0D;&#x4F1A;&#x66F4;&#x6539;&#x539F;&#x6765;&#x7684;&#x6570;&#x503C;&#x3002; </span></p>
</blockquote>
<h2 id="142-c&#x7C7B;&#x578B;&#x8F6C;&#x5316;"><a name="142-c&#x7C7B;&#x578B;&#x8F6C;&#x5316;" class="anchor-navigation-ex-anchor" href="#142-c&#x7C7B;&#x578B;&#x8F6C;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>14.2. <code>c++</code>&#x7C7B;&#x578B;&#x8F6C;&#x5316;</h2>
<h3 id="1421-&#x539F;&#x56E0;"><a name="1421-&#x539F;&#x56E0;" class="anchor-navigation-ex-anchor" href="#1421-&#x539F;&#x56E0;"><i class="fa fa-link" aria-hidden="true"></i></a>14.2.1. &#x539F;&#x56E0;</h3>
<blockquote>
<p>[!note]</p>
<ul>
<li><strong><code>c</code>&#x98CE;&#x683C;&#x7684;&#x8F6C;&#x6362;&#x4E0D;&#x5BB9;&#x6613;&#x67E5;&#x627E;</strong></li>
<li><strong>&#x6CA1;&#x6709;&#x5BF9;&#x8F6C;&#x5316;&#x8FDB;&#x884C;&#x5206;&#x7C7B;&#xFF0C;&#x5BB9;&#x6613;&#x51FA;&#x95EE;&#x9898;&#x3002;</strong></li>
</ul>
</blockquote>
<h3 id="1422-&#x5206;&#x7C7B;"><a name="1422-&#x5206;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#1422-&#x5206;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>14.2.2. &#x5206;&#x7C7B;</h3>
<table>
<thead>
<tr>
<th>&#x7C7B;&#x578B;&#x8F6C;&#x5316;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>static_cast</code></td>
<td>&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x3002;</td>
</tr>
<tr>
<td><code>reinterpreter_cast</code></td>
<td>&#x91CD;&#x65B0;&#x89E3;&#x91CA;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x3002;</td>
</tr>
<tr>
<td><code>dynamic_cast</code></td>
<td>&#x5B50;&#x7C7B;&#x548C;&#x7236;&#x7C7B;&#x4E4B;&#x95F4;&#x7684;&#x591A;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x3002;</td>
</tr>
<tr>
<td><code>const_cast</code></td>
<td>&#x53BB;&#x6389;<code>const</code>&#x5C5E;&#x6027;&#x8F6C;&#x6362;</td>
</tr>
</tbody>
</table>
<blockquote>
<p>[!note|style:flat]
<span style="color:red;font-weight:bold"> &#x8FD9;&#x4E9B;&#x8F6C;&#x6362;&#x5F62;&#x5F0F;&#xFF0C;&#x90FD;&#x80FD;&#x901A;&#x8FC7;<code>c</code>&#x98CE;&#x683C;&#x5B9E;&#x73B0;&#x3002; </span></p>
</blockquote>
<h3 id="1423-staticcast-&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><a name="1423-staticcast-&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;" class="anchor-navigation-ex-anchor" href="#1423-staticcast-&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>14.2.3. <code>static_cast</code> &#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;</h3>
<p><strong>&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#xFF1A;&#x5728;&#x7F16;&#x8BD1;&#x671F;&#x5185;&#x5373;&#x53EF;&#x51B3;&#x5B9A;&#x5176;&#x7C7B;&#x578B;&#x7684;&#x8F6C;&#x6362;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x822C;&#x53D8;&#x91CF;&#x95F4;&#x7684;&#x8F6C;&#x6362;&#x3002;</strong></p>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">float</span> dpi<span class="token punctuation">;</span>
<span class="token keyword">int</span> num3 <span class="token operator">=</span> <span class="token generic-function"><span class="token function">static_cast</span><span class="token generic class-name"><span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span></span></span> <span class="token punctuation">(</span>dPi<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h3 id="1424-dynamiccast"><a name="1424-dynamiccast" class="anchor-navigation-ex-anchor" href="#1424-dynamiccast"><i class="fa fa-link" aria-hidden="true"></i></a>14.2.4. <code>dynamic_cast</code></h3>
<p><strong>&#x7528;&#x4E8E;&#x591A;&#x6001;&#x4E2D;&#x7236;&#x5B50;&#x7C7B;&#x4E4B;&#x95F4;&#x7684;&#x591A;&#x6001;&#x8F6C;&#x6362;</strong></p>
<blockquote>
<p>[!tip]</p>
<ul>
<li><strong>&#x8F6C;&#x6362;&#x6210;&#x529F;&#xFF0C;&#x8FD4;&#x56DE;&#x8F6C;&#x6362;&#x540E;&#x7C7B;&#x578B;&#xFF1B;</strong></li>
<li><strong>&#x8F6C;&#x6362;&#x5931;&#x8D25;&#xFF0C;&#x8FD4;&#x56DE;&#x7A7A;&#x503C;</strong></li>
<li><span style="color:red;font-weight:bold"> &#x53EA;&#x80FD;&#x7528;&#x4E8E;<code>type *</code>&#x4E0E;<code>type &amp;</code>&#x8F6C;&#x6362;&#x3002; </span></li>
</ul>
</blockquote>
<pre class="language-"><code class="lang-cpp">Animal<span class="token operator">*</span> base <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span>
base <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token function">Cat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// &#x5C06;&#x2F57;&#x7C7B;&#x6307;&#x9488;&#x8F6C;&#x6362;&#x6210;&#x2F26;&#x5B50;&#x7C7B;&#xFF0C;</span>
Dog    <span class="token operator">*</span>pDog <span class="token operator">=</span> <span class="token generic-function"><span class="token function">dynamic_cast</span><span class="token generic class-name"><span class="token operator">&lt;</span>Dog<span class="token operator">*</span><span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span>base<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h3 id="1425-constcast"><a name="1425-constcast" class="anchor-navigation-ex-anchor" href="#1425-constcast"><i class="fa fa-link" aria-hidden="true"></i></a>14.2.5. <code>const_cast</code></h3>
<blockquote>
<p>[!note|style:flat]</p>
<ul>
<li><strong>&#x53BB;&#x9664;<code>const</code>&#x5C5E;&#x6027;</strong></li>
<li><span style="color:red;font-weight:bold"> &#x53EA;&#x80FD;&#x7528;&#x4E8E;<code>type *</code>&#x4E0E;<code>type &amp;</code>&#x8F6C;&#x6362;&#x3002; </span></li>
</ul>
</blockquote>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">volatile</span> <span class="token keyword">const</span> <span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">int</span><span class="token operator">&amp;</span> b <span class="token operator">=</span> <span class="token generic-function"><span class="token function">const_cast</span><span class="token generic class-name"><span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&amp;</span><span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
b <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
cout <span class="token operator">&lt;&lt;</span> a <span class="token operator">&lt;&lt;</span> endl<span class="token punctuation">;</span> <span class="token comment">// &#x503C;&#x4E3A; 2</span>

<span class="token keyword">const</span> <span class="token keyword">int</span> c<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">int</span><span class="token operator">&amp;</span> d <span class="token operator">=</span> <span class="token generic-function"><span class="token function">const_cast</span><span class="token generic class-name"><span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&amp;</span><span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
d <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
cout <span class="token operator">&lt;&lt;</span> c <span class="token operator">&lt;&lt;</span> endl<span class="token punctuation">;</span> <span class="token comment">// &#x503C;&#x4E3A; 1</span>
</code></pre>
<blockquote>
<p>[!note|style:flat]</p>
<ul>
<li><strong>&#x5F97;&#x7528;<code>volatile</code>&#x624D;&#x80FD;&#x8BA9;<code>a</code>&#x8F93;&#x51FA;&#x503C;&#x6539;&#x53D8;&#xFF0C;&#x4E0D;&#x7136;<code>a</code>&#x5230;&#x5E38;&#x91CF;&#x8868;&#x53D6;&#x503C;&#x3002;</strong></li>
<li><strong><code>a</code>&#x4E0E;<code>b</code>&#x5730;&#x5740;&#x4E00;&#x6837;</strong></li>
</ul>
</blockquote>
<h3 id="1426-reinterpretcast"><a name="1426-reinterpretcast" class="anchor-navigation-ex-anchor" href="#1426-reinterpretcast"><i class="fa fa-link" aria-hidden="true"></i></a>14.2.6. <code>reinterpret_cast</code></h3>
<p><strong>&#x5C31;&#x662F;&#x5BF9;&#x5185;&#x5B58;&#x8FDB;&#x884C;&#x91CD;&#x65B0;&#x89C4;&#x5212;&#xFF0C;&#x5E76;&#x4E0D;&#x4F1A;&#x6539;&#x53D8;&#x5185;&#x5B58;&#x91CC;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x503C;&#x3002;</strong></p>
<pre class="language-"><code class="lang-cpp"><span class="token keyword">int</span> num <span class="token operator">=</span> <span class="token number">0x00636261</span><span class="token punctuation">;</span><span class="token comment">//&#x7528;16&#x8FDB;&#x5236;&#x8868;&#x793A;32&#x4F4D;int&#xFF0C;0x61&#x662F;&#x5B57;&#x7B26;&apos;a&apos;&#x7684;ASCII&#x7801;</span>
<span class="token keyword">int</span> <span class="token operator">*</span> pnum <span class="token operator">=</span> <span class="token operator">&amp;</span>num<span class="token punctuation">;</span>
<span class="token keyword">char</span> <span class="token operator">*</span> pstr <span class="token operator">=</span> <span class="token generic-function"><span class="token function">reinterpret_cast</span><span class="token generic class-name"><span class="token operator">&lt;</span><span class="token keyword">char</span> <span class="token operator">*</span><span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span>pnum<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</code></pre>
<blockquote>
<p>[!note]</p>
<ul>
<li><strong><code>pstr</code>&#x4E0E;<code>pnum</code>&#x6307;&#x5411;&#x5730;&#x5740;&#x503C;&#x4E00;&#x6837;&#x3002;</strong></li>
<li><strong><code>pstr</code>&#x6309;&#x7167;<code>1</code>&#x5B57;&#x8282;&#x8BA1;&#x7B97;&#xFF1B;<code>pnum</code>&#x6309;&#x7167;<code>4</code>&#x5B57;&#x8282;&#x8BA1;&#x7B97;&#x3002;</strong></li>
</ul>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../cpp.html" class="navigation navigation-prev " aria-label="Previous page: C/C++">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="keyword_withNum.html" class="navigation navigation-next " aria-label="Next page: 二、关键字">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"一、基础概念","level":"2.1.1","depth":2,"next":{"title":"二、关键字","level":"2.1.2","depth":2,"path":"cpp/chapter/keyword_withNum.md","ref":"cpp/chapter/keyword_withNum.md","articles":[]},"previous":{"title":"C/C++","level":"2.1","depth":1,"path":"cpp/cpp.md","ref":"cpp/cpp.md","articles":[{"title":"一、基础概念","level":"2.1.1","depth":2,"path":"cpp/chapter/foundation_withNum.md","ref":"cpp/chapter/foundation_withNum.md","articles":[]},{"title":"二、关键字","level":"2.1.2","depth":2,"path":"cpp/chapter/keyword_withNum.md","ref":"cpp/chapter/keyword_withNum.md","articles":[]},{"title":"三、指针与引用","level":"2.1.3","depth":2,"path":"cpp/chapter/point_reference_withNum.md","ref":"cpp/chapter/point_reference_withNum.md","articles":[]},{"title":"四、面向对象","level":"2.1.4","depth":2,"path":"cpp/chapter/oop_withNum.md","ref":"cpp/chapter/oop_withNum.md","articles":[]},{"title":"五、内存","level":"2.1.5","depth":2,"path":"cpp/chapter/memory_withNum.md","ref":"cpp/chapter/memory_withNum.md","articles":[]},{"title":"六、进程与线程","level":"2.1.6","depth":2,"path":"cpp/chapter/process_withNum.md","ref":"cpp/chapter/process_withNum.md","articles":[]},{"title":"七、锁","level":"2.1.7","depth":2,"path":"cpp/chapter/locks_withNum.md","ref":"cpp/chapter/locks_withNum.md","articles":[]},{"title":"八、STL","level":"2.1.8","depth":2,"path":"cpp/chapter/stl_withNum.md","ref":"cpp/chapter/stl_withNum.md","articles":[]},{"title":"九、数据结构","level":"2.1.9","depth":2,"path":"cpp/chapter/dataStruction_withNum.md","ref":"cpp/chapter/dataStruction_withNum.md","articles":[]},{"title":"十、数组链表操作","level":"2.1.10","depth":2,"path":"cpp/chapter/array_list_withNum.md","ref":"cpp/chapter/array_list_withNum.md","articles":[]},{"title":"十一、目标查找","level":"2.1.11","depth":2,"path":"cpp/chapter/find_withNum.md","ref":"cpp/chapter/find_withNum.md","articles":[]},{"title":"十二、树","level":"2.1.12","depth":2,"path":"cpp/chapter/tree_withNum.md","ref":"cpp/chapter/tree_withNum.md","articles":[]},{"title":"十三、二叉树","level":"2.1.13","depth":2,"path":"cpp/chapter/binaryTree_withNum.md","ref":"cpp/chapter/binaryTree_withNum.md","articles":[]},{"title":"十四、动态规划","level":"2.1.14","depth":2,"path":"cpp/chapter/dynamicProgram_withNum.md","ref":"cpp/chapter/dynamicProgram_withNum.md","articles":[]},{"title":"十五、回溯算法","level":"2.1.15","depth":2,"path":"cpp/chapter/backtracking_withNum.md","ref":"cpp/chapter/backtracking_withNum.md","articles":[]},{"title":"十六、单调栈","level":"2.1.16","depth":2,"path":"cpp/chapter/monotoneStack_withNum.md","ref":"cpp/chapter/monotoneStack_withNum.md","articles":[]},{"title":"附录 工具库","level":"2.1.17","depth":2,"path":"cpp/chapter/toollib_withNum.md","ref":"cpp/chapter/toollib_withNum.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro-fixed","expandable-chapters-small","ancre-navigation","hide-element","code","splitter","insert-logo-link-website","-sharing","sharing-plus","prism","-highlight","flexible-alerts","lightbox","pageview-count","auto-scroll-table","katex-pro","favicon-absolute","sectionx","terminull-light","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"],"lang":{"flow":"typescript"}},"livereload":{},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"auto-scroll-table":{},"code":{"copyButtons":true},"terminull-light":{},"search-pro-fixed":{},"favicon-absolute":{"favicon":"image/ico.png","appleTouchIconPrecomposed152":"image/ico.png","appleTouchIconMore":{},"appleTouchIconPrecomposedMore":{}},"hide-element":{"elements":[".gitbook-link"]},"katex-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"lightbox":{"jquery":true,"sameUuid":false},"insert-logo-link-website":{"url":"image/logo.png","link":"https://space.bilibili.com/27206875","target":"_blank","style":"height: 230px"},"pageview-count":{},"ancre-navigation":{"showLevel":true,"associatedWithSummary":true,"mode":"float","printLog":false,"multipleH1":true,"float":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"expandable-chapters-small":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"qq":true,"all":["douban","facebook","google","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","whatsapp"],"douban":false,"facebook":false,"weibo":true,"whatsapp":false,"twitter":false,"pocket":false,"google":true,"qzone":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"海拉尔的三角","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"计算机笔记","links":{"sidebar":{"Github":"https://github.com/spite-triangle"}},"gitbook":"*"},"file":{"path":"cpp/chapter/foundation_withNum.md","mtime":"2021-09-14T15:43:12.436Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-14T15:43:23.052Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-terminull-light/terminull.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

